Append locale-specific suffixes to default rc file names, and look these
authorOwen Taylor <otaylor@redhat.com>
Mon, 14 Dec 1998 23:26:12 +0000 (23:26 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Mon, 14 Dec 1998 23:26:12 +0000 (23:26 +0000)
Mon Dec 14 16:10:05 1998  Owen Taylor  <otaylor@redhat.com>

* gtk/gtkrc.c (gtk_rc_init): Append locale-specific
suffixes to default rc file names, and look these
up in addition to the base filename, to facilitate
having the correct fontset per-locale.

move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc

* gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
New function to set a function to translate menu paths.

* gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
results of g_strsplit().

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkitemfactory.c
gtk/gtkitemfactory.h
gtk/gtkrc.c

index b8c05509a62b5e4fea26843e749dbfd5b152a299..cd3e02de726279092c12cb39407104b88a09b4df 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Mon Dec 14 16:10:05 1998  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkrc.c (gtk_rc_init): Append locale-specific
+       suffixes to default rc file names, and look these
+       up in addition to the base filename, to facilitate
+       having the correct fontset per-locale.
+
+       move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
+
+       * gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
+       New function to set a function to translate menu paths.
+
+       * gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
+       results of g_strsplit().
+
 1998-12-14  Nuno Ferreira  <nmrf@rnl.ist.utl.pt>
 
        * configure.in (ALL_LINGUAS): Added 'pt'.
index b8c05509a62b5e4fea26843e749dbfd5b152a299..cd3e02de726279092c12cb39407104b88a09b4df 100644 (file)
@@ -1,3 +1,18 @@
+Mon Dec 14 16:10:05 1998  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkrc.c (gtk_rc_init): Append locale-specific
+       suffixes to default rc file names, and look these
+       up in addition to the base filename, to facilitate
+       having the correct fontset per-locale.
+
+       move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
+
+       * gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
+       New function to set a function to translate menu paths.
+
+       * gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
+       results of g_strsplit().
+
 1998-12-14  Nuno Ferreira  <nmrf@rnl.ist.utl.pt>
 
        * configure.in (ALL_LINGUAS): Added 'pt'.
index b8c05509a62b5e4fea26843e749dbfd5b152a299..cd3e02de726279092c12cb39407104b88a09b4df 100644 (file)
@@ -1,3 +1,18 @@
+Mon Dec 14 16:10:05 1998  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkrc.c (gtk_rc_init): Append locale-specific
+       suffixes to default rc file names, and look these
+       up in addition to the base filename, to facilitate
+       having the correct fontset per-locale.
+
+       move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
+
+       * gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
+       New function to set a function to translate menu paths.
+
+       * gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
+       results of g_strsplit().
+
 1998-12-14  Nuno Ferreira  <nmrf@rnl.ist.utl.pt>
 
        * configure.in (ALL_LINGUAS): Added 'pt'.
index b8c05509a62b5e4fea26843e749dbfd5b152a299..cd3e02de726279092c12cb39407104b88a09b4df 100644 (file)
@@ -1,3 +1,18 @@
+Mon Dec 14 16:10:05 1998  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkrc.c (gtk_rc_init): Append locale-specific
+       suffixes to default rc file names, and look these
+       up in addition to the base filename, to facilitate
+       having the correct fontset per-locale.
+
+       move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
+
+       * gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
+       New function to set a function to translate menu paths.
+
+       * gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
+       results of g_strsplit().
+
 1998-12-14  Nuno Ferreira  <nmrf@rnl.ist.utl.pt>
 
        * configure.in (ALL_LINGUAS): Added 'pt'.
index b8c05509a62b5e4fea26843e749dbfd5b152a299..cd3e02de726279092c12cb39407104b88a09b4df 100644 (file)
@@ -1,3 +1,18 @@
+Mon Dec 14 16:10:05 1998  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkrc.c (gtk_rc_init): Append locale-specific
+       suffixes to default rc file names, and look these
+       up in addition to the base filename, to facilitate
+       having the correct fontset per-locale.
+
+       move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
+
+       * gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
+       New function to set a function to translate menu paths.
+
+       * gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
+       results of g_strsplit().
+
 1998-12-14  Nuno Ferreira  <nmrf@rnl.ist.utl.pt>
 
        * configure.in (ALL_LINGUAS): Added 'pt'.
index b8c05509a62b5e4fea26843e749dbfd5b152a299..cd3e02de726279092c12cb39407104b88a09b4df 100644 (file)
@@ -1,3 +1,18 @@
+Mon Dec 14 16:10:05 1998  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkrc.c (gtk_rc_init): Append locale-specific
+       suffixes to default rc file names, and look these
+       up in addition to the base filename, to facilitate
+       having the correct fontset per-locale.
+
+       move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
+
+       * gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
+       New function to set a function to translate menu paths.
+
+       * gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
+       results of g_strsplit().
+
 1998-12-14  Nuno Ferreira  <nmrf@rnl.ist.utl.pt>
 
        * configure.in (ALL_LINGUAS): Added 'pt'.
index b8c05509a62b5e4fea26843e749dbfd5b152a299..cd3e02de726279092c12cb39407104b88a09b4df 100644 (file)
@@ -1,3 +1,18 @@
+Mon Dec 14 16:10:05 1998  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkrc.c (gtk_rc_init): Append locale-specific
+       suffixes to default rc file names, and look these
+       up in addition to the base filename, to facilitate
+       having the correct fontset per-locale.
+
+       move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
+
+       * gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
+       New function to set a function to translate menu paths.
+
+       * gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
+       results of g_strsplit().
+
 1998-12-14  Nuno Ferreira  <nmrf@rnl.ist.utl.pt>
 
        * configure.in (ALL_LINGUAS): Added 'pt'.
index 009ec5d3b3eb6c83c0b82181a48a9f8820565d47..72f5b859d46c9ff28a6ce01585712013039555bb 100644 (file)
@@ -684,6 +684,9 @@ gtk_item_factory_finalize (GtkObject                  *object)
   g_free (ifactory->path);
   g_assert (ifactory->widget == NULL);
 
+  if (ifactory->translate_data && ifactory->translate_notify)
+    ifactory->translate_notify (ifactory->translate_data);
+  
   parent_class->finalize (object);
 }
 
@@ -893,11 +896,13 @@ gtk_item_factory_get_widget_by_action (GtkItemFactory   *ifactory,
 }
 
 static gboolean
-gtk_item_factory_parse_path (gchar  *str,
-                            gchar **path,
-                            gchar **parent_path,
-                            gchar **item)
+gtk_item_factory_parse_path (GtkItemFactory *ifactory,
+                            gchar          *str,
+                            gchar         **path,
+                            gchar         **parent_path,
+                            gchar         **item)
 {
+  gchar *translation;
   gchar *p, *q;
 
   *path = g_strdup (str);
@@ -922,7 +927,12 @@ gtk_item_factory_parse_path (gchar  *str,
     }
   *p = 0;
 
-  p = strrchr (str, '/');
+  if (ifactory->translate_func)
+    translation = ifactory->translate_func (str, ifactory->translate_data);
+  else
+    translation = str;
+                             
+  p = strrchr (translation, '/');
   p++;
 
   *item = g_strdup (p);
@@ -1006,7 +1016,7 @@ gtk_item_factory_create_item (GtkItemFactory           *ifactory,
        }
     }
 
-  if (!gtk_item_factory_parse_path (entry->path, 
+  if (!gtk_item_factory_parse_path (ifactory, entry->path, 
                                    &path, &parent_path, &name))
     return;
 
@@ -1599,3 +1609,19 @@ gtk_item_factory_parse_rc (const gchar     *file_name)
 
   close (fd);
 }
+
+void
+gtk_item_factory_set_translate_func (GtkItemFactory      *ifactory,
+                                    GtkTranslateFunc     func,
+                                    gpointer             data,
+                                    GtkDestroyNotify     notify)
+{
+  g_return_if_fail (ifactory != NULL);
+  
+  if (ifactory->translate_data && ifactory->translate_notify)
+    ifactory->translate_notify (ifactory->translate_data);
+      
+  ifactory->translate_func = func;
+  ifactory->translate_data = data;
+  ifactory->translate_notify = notify;
+}
index 1f93e1cbd5b8ccfa58eb634590b1812d404c2f0d..4110cc6f5c8e108846f840a7b32ceacd36e92d3b 100644 (file)
@@ -35,6 +35,8 @@ extern "C" {
 
 typedef void   (*GtkPrintFunc)            (gpointer             func_data,
                                            gchar               *str);
+typedef gchar * (*GtkTranslateFunc)       (const gchar         *path,
+                                           gpointer             func_data);
 typedef        void    (*GtkItemFactoryCallback)  ();
 typedef        void    (*GtkItemFactoryCallback1) (gpointer             callback_data,
                                            guint                callback_action,
@@ -63,6 +65,10 @@ struct _GtkItemFactory
   GtkAccelGroup                *accel_group;
   GtkWidget            *widget;
   GSList               *widgets_by_action;
+
+  GtkTranslateFunc       translate_func;
+  gpointer               translate_data;
+  GtkDestroyNotify       translate_notify;   
 };
 
 struct _GtkItemFactoryClass
@@ -185,6 +191,10 @@ void       gtk_item_factory_popup_with_data(GtkItemFactory         *ifactory,
                                         guint32                 time);
 gpointer gtk_item_factory_popup_data   (GtkItemFactory         *ifactory);
 gpointer gtk_item_factory_popup_data_from_widget (GtkWidget    *widget);
+void   gtk_item_factory_set_translate_func (GtkItemFactory      *ifactory,
+                                           GtkTranslateFunc     func,
+                                           gpointer             data,
+                                           GtkDestroyNotify     notify);
 
 /* Compatibility functions for deprecated GtkMenuFactory code
  */
index 91e5bd06ce84ba916715d640317419bdca00a544..1b33c235e514c5151ab609d8f00bfd32db2f69c5 100644 (file)
@@ -16,6 +16,7 @@
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+#include <X11/Xlocale.h>       /* so we get the right setlocale */
 #include <ctype.h>
 #include <unistd.h>
 #include <sys/stat.h>
@@ -24,6 +25,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+
 #include "gtkrc.h"
 #include "gtkbindings.h"
 #include "gtkthemes.h"
@@ -333,11 +335,12 @@ gtk_rc_add_initial_default_files (void)
          gtk_rc_add_default_file (files[i]);
          i++;
        }
+      g_strfreev (files);
     }
   else
     {
-      str = g_malloc (strlen(GTK_SYSCONFDIR) + strlen("/gtkrc") + 1);
-      sprintf (str, "%s%s", GTK_SYSCONFDIR, "/gtkrc");
+      str = g_malloc (strlen(GTK_SYSCONFDIR) + strlen("/gtk/gtkrc") + 1);
+      sprintf (str, "%s%s", GTK_SYSCONFDIR, "/gtk/gtkrc");
       gtk_rc_add_default_file (str);
 
       var = g_get_home_dir ();
@@ -398,7 +401,12 @@ gtk_rc_get_default_files (void)
 void
 gtk_rc_init (void)
 {
-  guint i;
+  gchar *locale_suffixes[3];
+  gint n_locale_suffixes = 0;
+  gint i, j;
+  char *locale = setlocale (LC_MESSAGES, NULL);
+  guint length;
+  char *p;
 
   rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
                                  (GCompareFunc) gtk_rc_style_compare);
@@ -409,13 +417,50 @@ gtk_rc_init (void)
 
   gtk_rc_add_initial_default_files ();
 
+  if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
+    {
+      /* Determine locale-specific suffixes for RC files
+       */
+      p = strchr (locale, '@');
+      length = p ? (p -locale) : strlen (locale);
+      
+      p = strchr (locale, '.');
+      if (p)
+       {
+         locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
+         length = p - locale;
+       }
+      
+      p = strchr (locale, '_');
+      if (p)
+       {
+         locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
+         length = p - locale;
+       }
+
+      locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
+    }
+  
   i = 0;
   while (gtk_rc_default_files[i] != NULL)
     {
+      /* Try to find a locale specific RC file corresponding to
+       * to parse before the default file.
+       */
+      for (j=n_locale_suffixes-1; j>=0; j--)
+       {
+         struct stat statbuf;
+         gchar *name = g_strconcat (gtk_rc_default_files[i],
+                                    ".",
+                                    locale_suffixes[j],
+                                    NULL);
+         gtk_rc_parse (name);
+       }
+
       gtk_rc_parse (gtk_rc_default_files[i]);
       i++;
     }
-}
+ }
 
 void
 gtk_rc_parse_string (const gchar *rc_string)